home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 6 / The Arsenal Files 6 (Arsenal Computer).ISO / prg_gen / aspell20.zip / ACROPSPL.PAS < prev    next >
Pascal/Delphi Source File  |  1996-01-19  |  5KB  |  182 lines

  1. unit Acropspl;
  2.  
  3. interface
  4.  
  5. { A silly wrapper component to hide the real code in the BaseASpl unit }
  6.  
  7. uses
  8.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  9.   Forms, Dialogs;
  10.  
  11.  
  12. type
  13.   TAcropSpell = class(TComponent)
  14.   private
  15.     { Private declarations }
  16.     DictDataPtr         : pointer;
  17.     FIsDictionaryOpen   : boolean;
  18.     FDictionaryMain     : string;
  19.     FDictionaryUser     : string;
  20.     FMaxSuggestions     : byte;
  21.   protected
  22.     { Protected declarations }
  23.   public
  24.     { Public declarations }
  25.     constructor Create(AOwner : TComponent); override;
  26.     procedure Free;
  27.     function OpenDictionary(Filename : STRING) : boolean;
  28.     function OpenUserDictionary(Filename : STRING) : integer;
  29.     procedure CloseDictionaries;
  30.     function GoodWord(TheWord : STRING) : BOOLEAN;
  31.     function AddWord(TheWord : STRING; DictID : integer) : BOOLEAN;
  32.     function SuggestCloseMatch(TheWord : STRING) : TStringList;
  33.     function SuggestPhoneme(TheWord : STRING) : TStringList;
  34.     function GetUserDictionaryList(DictID : integer) : TStringList;
  35.     function CloseUserDictionary(DictID : INTEGER) : BOOLEAN;
  36.     function DeleteUserDictionary(DictID : integer) : BOOLEAN;
  37.     procedure DeleteUserDictionaries;
  38.     procedure CloseUserDictonaries;
  39.     function BuildUserDictionary(Filename : STRING; WordList : TStringList) : INTEGER;
  40.     function IsDictionaryOpen : boolean;
  41.     procedure SetMaxSuggestions(Max : byte);
  42.   published
  43.     { Published declarations }
  44.     property DictionaryName : string read FDictionaryMain write FDictionaryMain;
  45.     property DictionaryUser : string read FDictionaryUser write FDictionaryUser;
  46.     property MaxSuggestions : byte read FMaxSuggestions write SetMaxSuggestions default 10;
  47.   end;
  48.  
  49. procedure Register;
  50.  
  51. implementation
  52.  
  53. uses BaseASpl;
  54.  
  55. procedure Register;
  56. begin
  57.   RegisterComponents('Samples', [TAcropSpell]);
  58. end;
  59.  
  60.  
  61. constructor TAcropSpell.Create(AOwner : TComponent);
  62. begin
  63.   inherited Create(AOwner);
  64.   FIsDictionaryOpen   := FALSE;
  65.   FDictionaryMain     := 'acrop.dct';
  66.   FDictionaryUser     := 'custom.dct';
  67.   FMaxSuggestions     := 10;
  68. end;
  69.  
  70. procedure TAcropSpell.Free;
  71. begin
  72.   if FIsDictionaryOpen then
  73.     CloseDictionaries;
  74.   inherited Free;
  75. end;
  76.  
  77. procedure OpenDefaultDictionary(AOwner : TAcropSpell);
  78. begin
  79.   with AOwner do
  80.     begin
  81.       FIsDictionaryOpen := OpenDictionary(FDictionaryMain);
  82.     end;
  83. end;
  84.  
  85. procedure TAcropSpell.SetMaxSuggestions(Max : byte);
  86. begin
  87.   if Max > 30 then
  88.     Max := 30;
  89.   FMaxSuggestions := Max;
  90. end;
  91.  
  92. function TAcropSpell.OpenDictionary(Filename : STRING) : boolean;
  93. begin
  94.   OpenDictionary := FALSE;
  95.   if FIsDictionaryOpen then
  96.     exit;
  97.   if BaseASpl.OpenDictionary(DictDataPtr, Filename) then
  98.     begin
  99.       FIsDictionaryOpen := TRUE;
  100.       FDictionaryMain   := Filename;
  101.       OpenDictionary    := TRUE;
  102.     end;
  103. end;
  104.  
  105. function TAcropSpell.OpenUserDictionary(Filename : STRING) : integer;
  106. begin
  107.   OpenUserDictionary := BaseASpl.OpenUserDictionary(DictDataPtr, Filename);
  108. end;
  109.  
  110. procedure TAcropSpell.CloseDictionaries;
  111. begin
  112.   if not FIsDictionaryOpen then
  113.     exit;
  114.   BaseASpl.CloseDictionaries(DictDataPtr);
  115.   FIsDictionaryOpen := FALSE;
  116. end;
  117.  
  118. function TAcropSpell.GoodWord(TheWord : STRING) : BOOLEAN;
  119. begin
  120.   if not FIsDictionaryOpen then
  121.     OpenDefaultDictionary(Self);
  122.   GoodWord := BaseASpl.GoodWord(DictDataPtr, TheWord);
  123. end;
  124.  
  125. function TAcropSpell.AddWord(TheWord : STRING; DictID : integer) : BOOLEAN;
  126. begin
  127.   if not FIsDictionaryOpen then
  128.     OpenDefaultDictionary(Self);
  129.   AddWord := BaseASpl.AddWord(DictDataPtr, TheWord, DictID);
  130. end;
  131.  
  132. function TAcropSpell.SuggestCloseMatch(TheWord : STRING) : TStringList;
  133. begin
  134.   if not FIsDictionaryOpen then
  135.     OpenDefaultDictionary(Self);
  136.   SuggestCloseMatch := BaseASpl.SuggestCloseMatch(DictDataPtr, TheWord, FMaxSuggestions);
  137. end;
  138.  
  139. function TAcropSpell.SuggestPhoneme(TheWord : STRING) : TStringList;
  140. begin
  141.   if not FIsDictionaryOpen then
  142.     OpenDefaultDictionary(Self);
  143.   SuggestPhoneme := BaseASpl.SuggestPhoneme(DictDataPtr, TheWord, FMaxSuggestions);
  144. end;
  145.  
  146. function TAcropSpell.GetUserDictionaryList(DictID : integer) : TStringList;
  147. begin
  148.   GetUserDictionaryList := BaseASpl.GetUserDictionaryList(DictDataPtr, DictID);
  149. end;
  150.  
  151. function TAcropSpell.CloseUserDictionary(DictID : INTEGER) : BOOLEAN;
  152. begin
  153.   CloseUserDictionary := BaseASpl.CloseUserDictionary(DictDataPtr, DictID);
  154. end;
  155.  
  156. function TAcropSpell.DeleteUserDictionary(DictID : integer) : BOOLEAN;
  157. begin
  158.   DeleteUserDictionary := BaseASpl.DeleteUserDictionary(DictDataPtr, DictID);
  159. end;
  160.  
  161. procedure TAcropSpell.DeleteUserDictionaries;
  162. begin
  163.   BaseASpl.DeleteUserDictionaries(DictDataPtr);
  164. end;
  165.  
  166. procedure TAcropSpell.CloseUserDictonaries;
  167. begin
  168.   BaseASpl.CloseUserDictionaries(DictDataPtr);
  169. end;
  170.  
  171. function TAcropSpell.BuildUserDictionary(Filename : STRING; WordList : TStringList) : integer;
  172. begin
  173.   BuildUserDictionary := BaseASpl.BuildUserDictionary(DictDataPtr, Filename, WordList);
  174. end;
  175.  
  176. function TAcropSpell.IsDictionaryOpen : boolean;
  177. begin
  178.   IsDictionaryOpen := FIsDictionaryOpen;
  179. end;
  180.  
  181. end.
  182.